<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" slot="detail" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="事件类型" prop="eventType">
              <a-input v-model="model.eventType" placeholder="请输入事件类型"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="事件位置" prop="eventLocation">
              <a-input v-model="model.eventLocation" placeholder="请输入事件位置"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="事件图片" prop="eventPicture">
              <j-image-upload v-model="model.eventPicture" isMultiple></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="事件发生时间"
                               prop="eventHappenTiem">
              <j-date v-model="model.eventHappenTiem" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"
                      placeholder="请选择事件发生时间" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="通道号" prop="channelId">
              <a-input v-model="model.channelId" placeholder="请输入通道号"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="事件地区" prop="eventArea">
              <a-input v-model="model.eventArea" placeholder="请输入事件地区"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="初审事件状态" prop="eventState">
              <j-dict-select-tag v-model="model.eventState" dictCode="event_state" placeholder="请选择初审事件状态"
                                 type="list"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="初审时间" prop="checkTime">
              <j-date v-model="model.checkTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"
                      disabled placeholder="请选择初审时间" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="初审人" prop="checkBy">
              <a-input v-model="model.checkBy" disabled placeholder="请输入初审人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="复审事件状态"
                               prop="eventStateRecheck">
              <j-dict-select-tag v-model="model.eventStateRecheck" dictCode="event_state_recheck" disabled
                                 placeholder="请选择复审事件状态" type="list"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="复审时间" prop="recheckTime">
              <j-date v-model="model.recheckTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss"
                      disabled placeholder="请选择复审时间" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="复审人" prop="recheckBy">
              <a-input v-model="model.recheckBy" disabled placeholder="请输入复审人"></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import {httpAction} from '@/api/manage'

export default {
  name: 'EventsDataForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {
        eventState: "0",
        eventStateRecheck: "0",
      },
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: "/sysEventsData/eventsData/add",
        edit: "/sysEventsData/eventsData/edit",
        queryById: "/sysEventsData/eventsData/queryById"
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>
